import collections
class Solution(object):
    def findLHS(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        c = collections.Counter(nums)
        d = list(c.keys())
        d.sort()
        if len(d) == 1:
            return 0
        max_len = 0
        for i in range(1, len(d)):
            if d[i] - d[i - 1] == 1:
                max_len = max(c[d[i]] + c[d[i - 1]], max_len)
        return max_len


data = Solution()
nums = [1, 3, 2, 2, 5, 2, 3, 7]
print(data.findLHS(nums))
